<template>


	<div class="animate__animated animate__zoomIn">

		<div style="height: 100px">
			<el-image :src="require('@/assets/blog1.png')" style="height: 100px"></el-image>
		</div>

		<el-row type="flex" class="row-bg" justify="center" style="height: 600px;background-color: #489BF2">
			<el-col :xl="6" :lg="7">
				<h2>欢迎来到留言管理系统</h2>

				<el-carousel :interval="4000" type="card" height="200px">
					<el-carousel-item v-for="item in imagesList" :key="item">
						<el-image
								style="width: 225px; height: 200px"
								:src="item"
								:preview-src-list="imagesList">
						</el-image>
					</el-carousel-item>
				</el-carousel>

				<p>相恨不如潮有信，相思始觉海非深。</p>
				<p>--浪淘沙·借问江潮与海水</p>

			</el-col>

			<el-col :span="1">
				<el-divider direction="vertical"></el-divider>
			</el-col>
			<el-col :xl="6" :lg="7">
				<el-form :model="loginForm" :rules="rules" ref="loginForm" label-width="80px">
					<el-form-item label="用户账号" prop="userName" style="width: 380px;font-weight:bold">
						<el-input v-model="loginForm.userName"></el-input>
					</el-form-item>
					<el-form-item label="用户名"  style="width: 380px;font-weight:bold">
						<el-input v-model="loginForm.name"></el-input>
					</el-form-item>
					<el-form-item label="密码" prop="password"  style="width: 380px;font-weight:bold">
						<el-input v-model="loginForm.password" type="password"></el-input>
					</el-form-item>
					<el-form-item label="确认密码" prop="confirmPassword"  style="width: 380px;font-weight:bold">
						<el-input v-model="loginForm.confirmPassword" type="password"></el-input>
					</el-form-item>


					<el-form-item class="style">
						<a href="/login" type="primary">已有账号？立即登录</a>
						<el-button  style="font-weight:bold" @click="submitForm('loginForm')">注册</el-button>

					</el-form-item>
				</el-form>
			</el-col>
		</el-row>
		<div>
			<span style="margin-top: 500px;margin-left: 550px">版权所有 ©2022 保留所有权利 2200139946 高武强</span>
		</div>
	</div>
</template>

<script>

	import qs from 'qs'

	export default {
		name: "Login",
		data() {
			const equalToPassword = (rule, value, callback) => {
				if (this.loginForm.password !== value) {
					callback(new Error("两次输入的密码不一致"));
				} else {
					callback();
				}
			};
			return {
				dialogVisible: false,
				loginForm: {
					userName: '',
					password: '',
					confirmPassword: '',
					name: ''
				},
				imagesList:[
					'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fseopic.699pic.com%2Fphoto%2F40029%2F4676.jpg_wh1200.jpg&refer=http%3A%2F%2Fseopic.699pic.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1672242205&t=ed881f76418c8913e3daf749f4e7dce2',
					'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Ftalkimages.cn%2Fimages%2Fmedium%2F20133001%2Ftkf001_132483.jpg&refer=http%3A%2F%2Ftalkimages.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1672242299&t=c06d9360ddca577a2dc8766b356b9617',
					'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fjocat.cn%2F2018%2F10%2F1-375.jpg%3F%3Dde96d9871539513480&refer=http%3A%2F%2Fjocat.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1672242360&t=0039123d092f3200b0a897a070623ffe'
				],
				rules: {
					userName: [
						{ required: true, message: '请输入用户名', trigger: 'blur' },
						{  max: 16, message: '用户名不能超过16位', trigger: 'blur' }
					],
					password: [
						{ required: true, message: '请输入密码', trigger: 'blur' },
						{ min: 6, max: 16, message: '密码必须为6-16位', trigger: 'blur' }
					],
					confirmPassword: [
						{ required: true, message: '请再次输入密码', trigger: 'blur' },
						{ required: true, validator: equalToPassword, trigger: "blur" }
					],
				},
				captchaImg: null
			};
		},
		methods: {
			submitForm(formName) {

				this.$confirm('是否确认继续注册?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {

					this.$refs[formName].validate((valid) => {
						if (valid) {
							this.$axios.post('/addUser?'+ qs.stringify(this.loginForm)).then(res => {

								console.log(res)

								// const jwt = res.headers['authorization']
								//
								// this.$store.commit('SET_TOKEN', jwt)
								this.$message({
									type: 'success',
									message: '注册成功!'
								});
								this.$router.push("/index")
							})

						} else {
							console.log('error submit!!');
							return false;
						}
					});
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消注册'
					});
				});

			},


		},
		created() {
			// this.getCaptcha()
		}
	}
</script>

<style scoped>

	.el-row {
		background-color: #fafafa;
		height: 100%;
		display: flex;
		align-items: center;
		text-align: center;
		justify-content: center;
	}

	.el-divider {
		height: 200px;
	}

	a{ padding:0 10px;}

	.captchaImg {
		float: left;
		margin-left: 8px;
		border-radius: 4px;
	}

	.style{
		margin-left: 8px;
	}

</style>
